<?php

class Model_KPI extends PhalApi_Model_NotORM {

    public function  lists($where, $offset = 0, $limit = 10, $orderby = "name desc") {
        return $this->getORM()
            ->select("*")
            ->where($where)
            ->limit($limit, $offset)
            ->order($orderby)
            ->fetchAll();
    }

    public function  count($where, $offset = 0, $limit = 10, $orderby = "name desc") {
        return $this->getORM()
            ->where($where)
            ->limit($limit, $offset)
            ->order($orderby)
            ->count("id");
    }

    public function delete($id) {
        return $this->getORM()
            ->where(["id" => $id])
            ->delete();
    }
    public function hasid($id) {
        return $this->getORM()
            ->where(["id" => $id])
            ->count("id");
    }
    public function getById($id) {
        return $this->getORM()
            ->select("*")
            ->where(["id" => $id])
            ->fetch();
    }

    public function isadded($contract_no) {
        return $this->getORM()
            ->where(["contract_no" => $contract_no])
            ->count("id");
    }

    public function add($data) {
        return $this->getORM()
            ->insert($data);

    }
    public function edit($data,$id) {
        return $this->getORM()
            ->where('id', $id)
            ->update($data);
    }

    protected function getTableName($id) {
        return 'sp_kpi';
    }
}
